<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .box {
        width: 200px;
        height: 200px;
        background-color: greenyellow;
      }
    </style>
  </head>
  <body>
    <button>按钮</button>
    <div class="box"></div>
    <input type="text" />
    <script>
      const btn = document.querySelector("button");
      btn.onclick = function () {
        console.log("点击了 function 函数1");
      };
      btn.onclick = () => {
        console.log("点击了 箭头函数1", this);
      };
      btn.addEventListener("click", () => {
        console.log("点击了 箭头函数2", this);
      });
      btn.addEventListener("click", function () {
        console.log("点击了 function函数2", this);
      });
      btn.addEventListener("click", (e) => {
        console.log("点击了 箭头函数2", e.currentTarget);
      });
      btn.addEventListener("click", function (e) {
        console.log("点击了 function函数2", e.currentTarget);
      });
      const box = document.querySelector(".box");
      box.addEventListener("mouseenter", () => {
        console.log("鼠标进入");
      });
      box.addEventListener("mouseleave", () => {
        console.log("鼠标离开");
      });
      const input = document.querySelector("input");
      input.addEventListener("focus", () => {
        console.log("获得焦点");
      });
      input.addEventListener("blur", () => {
        console.log("失去焦点");
      });
      input.addEventListener("keydown", () => {
        console.log("键盘按下");
      });
      input.addEventListener("keyup", (e) => {
        console.log("键盘弹起", e.key);
      });
    </script>
  </body>
</html>
